﻿@using EasyAbp.IdentityServerAdmin.Clients.Dtos
@using IdentityServer4.Models
<EditForm Model="ClientSecretList">
    <Card>
        <CardBody>

            @foreach (var clientSecret in ClientSecretList)
            {
                <Card Class="mb-2">
                    <CardBody>
                        <div class="form-group row">
                            <label class="col-sm-2">Secret Type</label>
                            <div class="col-sm-10">
                                <Select @bind-SelectedValue="clientSecret.Type">
                                    <SelectItem Value="@("SharedSecret")">Shared Secret</SelectItem>
                                </Select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2">Secret Value</label>
                            <div class="col-sm-10">
                                <TextEdit @bind-Text="clientSecret.Value"
                                          @onchange="@(() => {
                                                    clientSecret.Value = clientSecret.Value.Sha256();
                                                })">
                                </TextEdit>
                                <small class="form-text text-danger">
                                    Attension:Input value will encode with sha256.
                                </small>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2">Description</label>
                            <div class="col-sm-10">
                                <TextEdit @bind-Text="clientSecret.Description"></TextEdit>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2">Expiration</label>
                            <div class="col-sm-10">
                                <DateEdit @bind-Date="clientSecret.Expiration"></DateEdit>
                            </div>
                        </div>

                    </CardBody>
                    <CardFooter>
                        <Button  Color="Color.Danger" Clicked="() =>
                                                              { ClientSecretList.Remove(clientSecret);
                                                                ClientSecretListChanged.InvokeAsync(ClientSecretList);
                                                              }">
                            Delete
                        </Button>
                    </CardFooter>
                </Card>
            }

        </CardBody>
        <CardFooter>
            <Button
                    Color="Color.Primary"

                    Clicked="@(() => { ClientSecretList.Add(new ClientSecretDto()); ClientSecretListChanged.InvokeAsync(ClientSecretList); })">
                New Secret
            </Button>
        </CardFooter>
    </Card>
</EditForm>


@code {

    [Parameter]
    public List<ClientSecretDto> ClientSecretList { get; set; } = new List<ClientSecretDto>();

    [Parameter]
    public EventCallback<List<ClientSecretDto>> ClientSecretListChanged { get; set; }


}